import { request } from "../request";

/**
 * 上传AI资源接口返回结构
 */
export interface UploadRes {
    code: number;
    message: string;
    data: {
        resourceId: number;
        chatId: number;
        userId: number;
        ossUrl: string;
        type: string;
        title: string;
        createdAt: Record<string, unknown>;
    };
    timestamp: Record<string, unknown>;
}

/**
 * 上传AI资源
 * @param params 上传参数
 * @returns 上传结果
 */
export const uploadAiResourceAPI = async (params: {
    fileType: string;
    chatID: number;
    userID: number;
    fileUrl: string;
    title:string
}): Promise<UploadRes> => {
    const { fileType, chatID, userID, fileUrl ,title} = params;
    const token = localStorage.getItem("token");

    const formData = new FormData();
    formData.append("fileType", fileType);
    formData.append("chatID", String(chatID));
    formData.append("userID", String(userID));
    formData.append("title",String(title))
    formData.append("fileUrl", String(fileUrl));

    return request("/api/ai-resources/upload", {
        method: "post",
        data: formData,
        headers: {
            Authorization: `Bearer ${token}`
            // 注意：当使用 FormData 时，**不要手动设置 Content-Type**，浏览器会自动处理。
        }
    });
};